import { createI18n } from 'vue-i18n'
import messages from './messages'
import store from '../store'

const i18n = createI18n({
    locale: store.get("config.locale") as string || 'zh',
    fallbackLocale: 'en',
    messages: messages,
})
export const $t = i18n.global.t

export const toggleLocale = (value: any) => {
    i18n.global.locale = value;
}

export const mergeProjectLocale = () => {
    let locales: any = store.get("locales") || {}
    for (let k in locales) {
        i18n.global.mergeLocaleMessage(k, locales[k])
    }
}